<?php
class ProducerModel {

	private $m_producerDAL;
	
	public function __construct(){
		$this->m_producerDAL = new ProducerDAL();
	}
	public function GetPositions($a_variables, $a_urlParameters){
		
		$string = "";
		
		$id = 0;
		
		if(count($a_urlParameters)==1 ){
			$id = intval($a_urlParameters[0]);	
		}
		if(isset($a_urlParameters[0]) && $id != 0 ){
			
			$result = $this->m_producerDAL->GetPositionById($a_urlParameters[0]);		
			
		}elseif(count($a_urlParameters)==0){			
			$result = $this->m_producerDAL->GetAllPositions();
		}else{
			
			RestUtils::sendResponse('400', "<error>Felaktiga parametrar</error>", 'text/xml');
		}
		
		return $result;
	}
	
	public function CreatePosition($a_requestVariables){
		if($a_requestVariables['pId'] == null ||$a_requestVariables['longitude'] == null ||$a_requestVariables['latitude'] == null || $a_requestVariables['description'] == null){
			RestUtils::sendResponse('400', "<error>Du måste ange alla parametrar</error>", 'text/xml');
		}
		return $this->m_producerDAL->CreatePosition($a_requestVariables['pId'], 
											$a_requestVariables['longitude'], 
											$a_requestVariables['latitude'], 
											$a_requestVariables['description']);
	}
	
	public function UpdatePosition($a_requestVariables, $a_id){
			
		if($a_id == null ||$a_requestVariables['longitude'] == null ||$a_requestVariables['latitude'] == null || $a_requestVariables['description'] == null){
			RestUtils::sendResponse('400', "<error>Du måste ange alla parametrar</error>", 'text/xml');
		}
		return $this->m_producerDAL->UpdatePosition($a_id, 
											$a_requestVariables['longitude'], 
											$a_requestVariables['latitude'], 
											$a_requestVariables['description']);
	}
	
	public function DeletePosition($a_id){
		return $this->m_producerDAL->DeletePosition($a_id);
	}	
}